package com.zretc.service.impl;

import java.util.List;

import com.zretc.dao.AdminDao;
import com.zretc.dao.impl.AdminDaoImpl;
import com.zretc.entity.Admin;
import com.zretc.service.AdminService;
import com.zretc.tools.MD5Util;

public class AdminServiceImpl implements AdminService {

	AdminDao adminDao=new AdminDaoImpl();
	@Override
	public boolean addAdmin(Admin admin) {
		// 增加用户，先判断这个用户是否存在；如果用户已经存在，这不不执行添加操作；
		if(admin == null) {
			return false;
		}
		if (adminDao.getAdminByName(admin.getAdminname()) != null) {
			return false;
		}
		// 如果用户不存在，再将这个用户添加到数据库。
		boolean flag = adminDao.addAdmin(admin);
		return flag;
	}

	@Override
	public List<Admin> getAdmin(String keywords) {
		// TODO Auto-generated method stub
		return adminDao.getAdmin(keywords);
	}

	@Override
	public Admin adminlogin(String adminname, String adminpwd) {
		// TODO Auto-generated method stub
		adminpwd = MD5Util.getEncodeByMd5(adminpwd);
		return adminDao.getAdminByNameAndPwd(adminname, adminpwd);
	}

}
